package com.miraclengine.xml;

import java.util.HashMap;
import java.util.Map;

import com.miraclengine.utils.Debug;
import com.miraclengine.utils.GlobalStatic;

public class DataRow {
	
	private String TAG = DataRow.class.getSimpleName();

	 Map<String, Object> properties = null;
	 
	 public DataRow() {
		 properties = new HashMap<String, Object>();
	 }
	 
	 public Map<String, Object> getProperties() {
		 return this.properties;
	 }
	 
	 public void put(String key, Object value) {
		 this.properties.put(DataTable.convc(key), value);
	 }
	 
	 public String get(String k) {
		 String ret = "";
		 
		 try  {
			 String temp = this.properties.get(DataTable.convc(k)).toString();
			 //value에 들어있는 잘못된 공백 삭제...
			 temp = temp.replace("\n","");
			 temp = temp.replace("\t", "");
			 //value에 들어있는 newLine값을 
			 ret = temp.replaceAll(GlobalStatic.newLineValue, "\n");
			 
			 return ret;
		 } catch(Exception e) {
			 Debug.d(TAG, "get -> 없는 키로 데이터를 찾으려고 하네!!");
			 return "Hello";
			 //return this.properties.get(DataTable.convc(k)).toString();
		 }
	 }
	 
	 @SuppressWarnings("unchecked")
	public HashMap<String, String> getObject(String k) {
		 return (HashMap<String, String>)this.properties.get(DataTable.convc(k));
	 }
	
	 public long getLong(String k) {
		try {
			return Long.parseLong(this.get(k));
		} catch(Exception err) {
			return -1;
		}
	 }
	 
	 public int getInt(String k) {
		 try {
			 return Integer.parseInt(this.get(k));
		 } catch(Exception err) {
			 return -1;
		 }
	 }
	 
	 /**
	  * 특정 값을 변경한다.
	  */
	 public void changeRow(String key, Object value) {
		 this.properties.remove(key);
		 this.properties.put(key, value);
	 }
}
